from flask import Flask, make_response, jsonify, g, current_app as app,Blueprint,request
from sqlalchemy import select,insert,update,func,join
from sqlalchemy.sql import text
from eim.tools.dbtool import DBTool
from eim import db
from eim.tools.searchtool import SearchCondition,SearchConditionList,MatchLogic,PartnerRS
from eim.result.simple_result import SimpleResult

nclog=Blueprint("nclog","nclog",__name__,url_prefix="/nclog")

@nclog.route("/appendNewLog",methods=["PUT"])
def appendNewLog():
    """
    添加新的日志信息
    """
    try:
        res = request.json
        if(not isinstance(res,dict)):
            raise Exception("新增日志的参数必须为jason格式")
        ks = res.keys()
        if( not "precode" in ks) or ( not "createtime" in ks) or (not "hostname"in ks) or (not "company"in ks) or (not "logversion" in ks) or (not "modulename" in ks) or (not "serverity" in ks) or (not "brief" in ks) or (not "infotype" in ks) or (not "serialno" in ks) or (not "description" in ks):
            raise Exception("缺少必要的字段信息")
        from eim.Services.netcomlog import NetComLog
        ncl = NetComLog(db)
        id = ncl.appendNewLog(res["precode"],res["createtime"],res["hostname"],res["company"],res["logversion"],res["modulename"],res["serverity"],res["brief"],res["infotype"],res["serialno"],res["description"])
        return SimpleResult(status="T",value=id).toDict()
    except Exception as es:
        info = str(es)
        app.logger.error(info)
        return SimpleResult(msg=info).toDict()